home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / text / less-278.lha / less-278 / src.lha / source / less.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-01  |  5.8 KB  |  245 lines

  1. /*
  2.  * Copyright (c) 1984,1985,1989,1994,1995  Mark Nudelman
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice in the documentation and/or other materials provided with 
  12.  *    the distribution.
  13.  *
  14.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  15.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  17.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  18.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  19.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
  20.  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
  21.  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
  22.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
  23.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
  24.  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  */
  26.  
  27.  
  28. /*
  29.  * Standard include file for "less".
  30.  */
  31.  
  32. /*
  33.  * Include the file of compile-time options.
  34.  * The <> make cc search for it in -I., not srcdir.
  35.  */
  36. #include <defines.h>
  37.  
  38. /*
  39.  * Language details.
  40.  */
  41. #if HAVE_VOID
  42. #define    VOID_POINTER    void *
  43. #else
  44. #define    VOID_POINTER    char *
  45. #define    void  int
  46. #endif
  47.  
  48. #define    public        /* PUBLIC FUNCTION */
  49.  
  50. /* Library function declarations */
  51.  
  52. #if HAVE_SYS_TYPES_H
  53. #include <sys/types.h>
  54. #endif
  55. #if HAVE_STDIO_H
  56. #include <stdio.h>
  57. #endif
  58. #if HAVE_FCNTL_H
  59. #include <fcntl.h>
  60. #endif
  61. #if HAVE_UNISTD_H
  62. #include <unistd.h>
  63. #endif
  64. #if HAVE_CTYPE_H
  65. #include <ctype.h>
  66. #endif
  67. #if STDC_HEADERS
  68. #include <stdlib.h>
  69. #include <string.h>
  70. #endif
  71.  
  72. #if !STDC_HEADERS
  73. char *getenv();
  74. off_t lseek();
  75. VOID_POINTER calloc();
  76. void free();
  77. #endif
  78.  
  79. #if !HAVE_UPPER_LOWER
  80. #define    isupper(c)    ((c) >= 'A' && (c) <= 'Z')
  81. #define    islower(c)    ((c) >= 'a' && (c) <= 'z')
  82. #define    toupper(c)    ((c) - 'a' + 'A')
  83. #define    tolower(c)    ((c) - 'A' + 'a')
  84. #endif
  85.  
  86. #ifndef NULL
  87. #define    NULL    0
  88. #endif
  89.  
  90. #ifndef TRUE
  91. #define    TRUE        1
  92. #endif
  93. #ifndef FALSE
  94. #define    FALSE        0
  95. #endif
  96.  
  97. #define    OPT_OFF        0
  98. #define    OPT_ON        1
  99. #define    OPT_ONPLUS    2
  100.  
  101. #ifndef HAVE_MEMCPY
  102. #ifndef memcpy
  103. #define    memcpy(to,from,len)    bcopy((from),(to),(len))
  104. #endif
  105. #endif
  106.  
  107. #define    BAD_LSEEK    ((off_t)-1)
  108.  
  109. /*
  110.  * Special types and constants.
  111.  */
  112. typedef long        POSITION;
  113. /*
  114.  * {{ Warning: if POSITION is changed to other than "long",
  115.  *    you may have to change some of the printfs which use "%ld"
  116.  *    to print a variable of type POSITION. }}
  117.  */
  118.  
  119. #define    NULL_POSITION    ((POSITION)(-1))
  120.  
  121. /*
  122.  * Flags for open()
  123.  */
  124. #if MSOFTC || OS2
  125. #define    OPEN_READ    (O_RDONLY|O_BINARY)
  126. #else
  127. #define    OPEN_READ    (0)
  128. #endif
  129. #if MSOFTC || OS2
  130. #define    OPEN_APPEND    (O_APPEND|O_WRONLY)
  131. #else
  132. #define    OPEN_APPEND    (1)
  133. #endif
  134.  
  135. #if MSOFTC || OS2
  136. #define    OPEN_TTYIN()    open("CON", O_TEXT|O_RDONLY)
  137. #else
  138. #define    OPEN_TTYIN()    open("/dev/tty", 0)
  139. #endif
  140.  
  141. /*
  142.  * An IFILE represents an input file.
  143.  */
  144. #define    IFILE        VOID_POINTER
  145. #define    NULL_IFILE    ((IFILE)NULL)
  146.  
  147. /*
  148.  * The structure used to represent a "screen position".
  149.  * This consists of a file position, and a screen line number.
  150.  * The meaning is that the line starting at the given file
  151.  * position is displayed on the ln-th line of the screen.
  152.  * (Screen lines before ln are empty.)
  153.  */
  154. struct scrpos
  155. {
  156.     POSITION pos;
  157.     int ln;
  158. };
  159.  
  160. typedef union parg
  161. {
  162.     char *p_string;
  163.     int p_int;
  164. } PARG;
  165.  
  166. #define    NULL_PARG    ((PARG *)NULL)
  167.  
  168. struct textlist
  169. {
  170.     char *string;
  171.     char *endstring;
  172. };
  173.  
  174. #define    EOI        (-1)
  175.  
  176. #define    READ_INTR    (-2)
  177.  
  178. /* How quiet should we be? */
  179. #define    NOT_QUIET    0    /* Ring bell at eof and for errors */
  180. #define    LITTLE_QUIET    1    /* Ring bell only for errors */
  181. #define    VERY_QUIET    2    /* Never ring bell */
  182.  
  183. /* How should we prompt? */
  184. #define    PR_SHORT    0    /* Prompt with colon */
  185. #define    PR_MEDIUM    1    /* Prompt with message */
  186. #define    PR_LONG        2    /* Prompt with longer message */
  187.  
  188. /* How should we handle backspaces? */
  189. #define    BS_SPECIAL    0    /* Do special things for underlining and bold */
  190. #define    BS_NORMAL    1    /* \b treated as normal char; actually output */
  191. #define    BS_CONTROL    2    /* \b treated as control char; prints as ^H */
  192.  
  193. /* How should we search? */
  194. #define    SRCH_FORW    0001    /* Search forward from current position */
  195. #define    SRCH_BACK    0002    /* Search backward from current position */
  196. #define    SRCH_FIND_ALL    0010    /* Find and highlight all matches */
  197. #define    SRCH_NOMATCH    0100    /* Search for non-matching lines */
  198. #define    SRCH_PAST_EOF    0200    /* Search past end-of-file, into next file */
  199. #define    SRCH_FIRST_FILE    0400    /* Search starting at the first file */
  200.  
  201. #define    SRCH_REVERSE(t)    (((t) & SRCH_FORW) ? \
  202.                 (((t) & ~SRCH_FORW) | SRCH_BACK) : \
  203.                 (((t) & ~SRCH_BACK) | SRCH_FORW))
  204.  
  205. /* */
  206. #define    NO_MCA        0
  207. #define    MCA_DONE    1
  208. #define    MCA_MORE    2
  209.  
  210. #define    CC_OK        0    /* Char was accepted & processed */
  211. #define    CC_QUIT        1    /* Char was a request to abort current cmd */
  212. #define    CC_ERROR    2    /* Char could not be accepted due to error */
  213. #define    CC_PASS        3    /* Char was rejected (internal) */
  214.  
  215. /* Special chars used to tell put_line() to do something special */
  216. #define    AT_NORMAL    (0)
  217. #define    AT_UNDERLINE    (1)
  218. #define    AT_BOLD        (2)
  219. #define    AT_BLINK    (3)
  220. #define    AT_INVIS    (4)
  221. #define    AT_STANDOUT    (5)
  222.  
  223. #define    CONTROL(c)    ((c)&037)
  224. #define    ESC        CONTROL('[')
  225.  
  226. #define    SIGNAL(sig,func)    signal(sig,func)
  227.  
  228. #define    S_INTERRUPT    01
  229. #define    S_STOP        02
  230. #define S_WINCH        04
  231. #define    ABORT_SIGS()    (sigs & (S_INTERRUPT|S_STOP))
  232.  
  233. #define    QUIT_OK        0
  234. #define    QUIT_ERROR    1
  235. #define    QUIT_SAVED_STATUS (-1)
  236.  
  237. /* filestate flags */
  238. #define    CH_CANSEEK    001
  239. #define    CH_KEEPOPEN    002
  240. #define    CH_POPENED    004
  241.  
  242. #define    ch_zero()    ((POSITION)0)
  243.  
  244. #include "funcs.h"
  245.